package com.founder.gateway.controller;

import com.founder.gateway.orm.fzapi.bean.entity.BlogEntity;
import com.founder.gateway.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/******************************************************************************
 * @Package: [com.founder.gateway.controller.BlogController]
 * @ClassName: [BlogController]
 * @Description: [一句话描述该类的功能]
 * @Author: [fengli@founder.com.cn]  
 * @CreateDate: [2019/1/11 17:13]   
 * @UpdateUser: [fengli@founder.com.cn (如多次修改保留历史记录，增加修改记录)]   
 * @UpdateDate: [2019/1/11 17:13，(如多次修改保留历史记录，增加修改记录)]   
 * @UpdateRemark: [说明本次修改内容, (如多次修改保留历史记录 ， 增加修改记录)]
 * @Version: [v1.0]
 * ${tags}
 */
@RestController
public class BlogController {
    @Autowired
    private BlogService blogService;

    //查询博客的完整信息
    @ResponseBody
    @RequestMapping("/getBlogInfo")
    public Map<String, BlogEntity> getBlogInfo(){
        Map<String,BlogEntity> blogEntityMap=new HashMap<>();
        BlogEntity blogEntity= blogService.getBlogInfo("4fc766f8d3814ba8818a02e2f21d16db");
        blogEntityMap.put("result", blogEntity);
        return blogEntityMap;
    }

    @RequestMapping("/createBlog")
    //@GetMapping("/createBlog/{id}")
    public void createBlog(@RequestParam(name = "userId") String id, @RequestParam(name = "content") String content){
        BlogEntity blogEntity=new BlogEntity();
        blogEntity.setBlog(content);
        blogEntity.setUserId(id);
        blogService.addBlog(blogEntity);
    }

    @RequestMapping("/updateContent")
    public Map<String,BlogEntity> updateContent(@RequestParam(name = "id")String id,@RequestParam(name = "content")String content){
        BlogEntity blogEntity=new BlogEntity();
        blogEntity.setBlog(content);
        blogEntity.setUserId(id);
        blogService.updateBlog(blogEntity);
        Map<String,BlogEntity> result=new HashMap<>();
        result.put("result", blogEntity);
        return result;
    }
}
